import { stores } from '@/stores'
import { Toast } from 'antd-mobile'
import { makeAutoObservable } from 'mobx'
import { history } from 'umi'
import { resetPwd } from '../api'
import type { ResetPwdParamsType } from '../api/interface'
// import { stores } from '@/stores'
// import * as Storage from '@/storage'
class Store {
    constructor() {
        makeAutoObservable(this)
    }

    updatePassword = async (params: ResetPwdParamsType) => {
        const { getUserInfo, updateUserInfo } = stores.userStore
        await resetPwd(params)
        Toast.show({
            content: '修改成功',
            position: 'top',
        })

        if (getUserInfo?.is_default_password === 1) {
            updateUserInfo({
                ...getUserInfo,
                is_default_password: 0,
            })
        }

        history.push({ pathname: '/' })
    }
}

export default Store
